package wangwenjun.phase1.close;

import java.util.concurrent.TimeUnit;

/**
 * @author ChangLiang
 * @date 2020/5/29
 */
public class InterruptThreadExitV1 {

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread()
        {
            @Override
            public void run()
            {
                System.out.println("I will start work");
                // 注意：在这里面不要执行可中断的方法
                while (!isInterrupted()) {

                }
                System.out.println("I will be exiting.");
            }
        };
        t.start();
        TimeUnit.SECONDS.sleep(5);
        System.out.println("System will be shutdown.");
        t.interrupt();
    }
}
